package com.candoit.webapps.pricing.listeners;

import javax.faces.component.UIComponent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;

import com.candoit.webapps.pricing.model.CriterioDistribucion;
import com.candoit.webapps.pricing.util.QueryUtil;

public class ChangeCantidadCriterioListener implements ValueChangeListener {  
	public void processValueChange(ValueChangeEvent event)
			throws AbortProcessingException {
		 UIComponent c = (UIComponent) event.getSource();  
		 String[] ids = c.getId().split("_");
		 Object oldValue = event.getOldValue();
	     Object newValue = event.getNewValue();
	      if (oldValue != newValue)
	        {	
	           Double cantidad = Double.valueOf((String) newValue);   
	           CriterioDistribucion criterio = QueryUtil.getInstance().getCriterioDistribucionById(Integer.valueOf(ids[1]));
	           criterio.setTotalCriterio(cantidad);
	        }        
		
	}  
}  


